/// <summary>**********************************************************************
/// /* FilterInputStream.java -- Base class for classes that filter input
/// /*
/// /* Copyright (c) 1998 Free Software Foundation, Inc.
/// /* Written by Aaron M. Renn (arenn@urbanophile.com)
/// /*
/// /* This library is free software; you can redistribute it and/or modify
/// /* it under the terms of the GNU Library General Public License as published 
/// /* by the Free Software Foundation, either version 2 of the License, or
/// /* (at your option) any later verion.
/// /*
/// /* This library is distributed in the hope that it will be useful, but
/// /* WITHOUT ANY WARRANTY; without even the implied warranty of
/// /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
/// /* GNU Library General Public License for more details.
/// /*
/// /* You should have received a copy of the GNU Library General Public License
/// /* along with this library; if not, write to the Free Software Foundation
/// /* Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
/// /************************************************************************
/// </summary>
using System;
using System.IO;

namespace NDODS.Util {
    /// <summary> This is the common superclass of all standard classes that filter 
    /// input.  It acts as a layer on top of an underlying <code>InputStream</code>
    /// and simply redirects calls made to it to the subordinate InputStream
    /// instead.  Subclasses of this class perform additional filtering
    /// functions in addition to simply redirecting the call.
    /// <p>
    /// This class is not abstract.  However, since it only redirects calls
    /// to a subordinate <code>InputStream</code> without adding any functionality on top
    /// of it, this class should not be used directly.  Instead, various
    /// subclasses of this class should be used.  This is enforced with a
    /// protected constructor.  Do not try to hack around it.
    /// <p>
    /// When creating a subclass of <code>FilterInputStream</code>, override the
    /// appropriate methods to implement the desired filtering.  However, note
    /// that the <code>Read(byte[])</code> method does not need to be overridden
    /// as this class redirects calls to that method to 
    /// <code>Read(byte[], int, int)</code> instead of to the subordinate
    /// <code>InputStream Read(byte[])</code> method.
    /// 

    /// <version>  0.0
    /// 
    /// </version>
    /// <author>  Aaron M. Renn (arenn@urbanophile.com)
    /// </author>
    /// </summary>
    public class FilterInputStream : BinaryReader {
        /// <summary>*********************************************************************</summary>
        /*
		* Instance Variables
		*/
        /// <summary> This is the subordinate <code>InputStream</code> to which method calls
        /// are redirected
        /// </summary>
        //protected internal Stream BaseStream;

        /// <summary>*********************************************************************</summary>
        /*
		* Constructors
		*/
        /// <summary> Create a <code>FilterInputStream</code> with the specified subordinate
        /// <code>InputStream</code>.
        /// 
        /// </summary>
        /// <param name="in_Renamed">The subordinate <code>InputStream</code>
        /// </param>
        protected internal FilterInputStream(Stream in_Renamed) : base(in_Renamed) {
            
        }

        /// <summary>*********************************************************************</summary>
        /*
		* Instance Methods
		*/
        /// <summary> Calls the <code>in.mark(int)</code> method.
        /// 
        /// </summary>
        /// <param name="readlimit">The parameter passed to <code>in.mark(int)</code>
        /// </param>
        public virtual void Mark(int readlimit) {
            return;
        }

        /// <summary>*********************************************************************</summary>
        /// <summary> Calls the <code>in.markSupported()</code> method.
        /// 
        /// </summary>
        /// <returns> <code>true</code> if mark/reset is supported, <code>false</code> otherwise
        /// </returns>
        public virtual bool MarkSupported()
        {
            return false;
        }

        /// <summary>*********************************************************************</summary>
        /// <summary> Calls the <code>in.reset()</code> method.
        /// 
        /// </summary>
        /// <exception cref="IOException">If an error occurs
        /// </exception>
        public virtual void Reset()
        {
            throw new IOException("Mark not supported in this class");
        }

        /// <summary>*********************************************************************</summary>
        /// <summary> Calls the <code>in.available()</code> method.
        /// 
        /// </summary>
        /// <returns> The value returned from <code>in.available()</code>
        /// 
        /// </returns>
        /// <exception cref="IOException">If an error occurs
        /// </exception>
        //UPGRADE_NOTE: The equivalent of method 'java.io.InputStream.available' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"
        public virtual int Available()
        {
            long available;
            available = ( BaseStream).Length - ( BaseStream).Position;
            return (int)available;
        }

        /// <summary>*********************************************************************</summary>
        /// <summary> Calls the <code>in.skip(long)</code> method
        /// 
        /// </summary>
        /// <param name="num_bytes">requested number of bytes to skip. 
        /// 
        /// </param>
        /// <returns> The value returned from <code>in.skip(long)</code>
        /// 
        /// </returns>
        /// <exception cref="IOException">If an error occurs
        /// </exception>
        //UPGRADE_NOTE: The equivalent of method 'java.io.InputStream.skip' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"
        public virtual long Skip(long num_bytes) {
            Stream temp_Stream;
            Int64 temp_Int64;
            temp_Stream = BaseStream;
            temp_Int64 = temp_Stream.Position;
            temp_Int64 = temp_Stream.Seek(num_bytes, SeekOrigin.Current) - temp_Int64;
            return temp_Int64;
        }



        /// <summary>*********************************************************************</summary>
        /// <summary> Calls the <code>Read(byte[], int, int)</code> overloaded method.  Note that 
        /// this method does not redirect its call directly to a corresponding
        /// method in <code>in</code>.  This allows subclasses to override only the
        /// three argument version of <code>Read</code>.
        /// 
        /// </summary>
        /// <param name="buf">The buffer to Read bytes into
        /// 
        /// </param>
        /// <returns> The value retured from <code>in.Read(byte[], int, int)</code>
        /// 
        /// </returns>
        /// <exception cref="IOException">If an error occurs
        /// </exception>
        //UPGRADE_NOTE: The equivalent of method 'java.io.InputStream.Read' is not an override method. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1143'"
        public virtual int Read(byte[] buf) {
            return (Read(buf, 0, buf.Length));
        }

      

        /// <summary>
        /// This method closes the input stream by closing the input stream that
        /// this object is filtering.  Future attempts to access this stream may
        /// throw an exception.
        /// <exception cref="IOException">If an error occurs
        /// </exception>
        /// </summary>
        public override void Close() {
            (BaseStream).Close();
        }


        /// <summary>
        /// IsRead in the buffer for the underline stream
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public override Int32 Read(Byte[] buffer, Int32 offset, Int32 count) {
            return BaseStream.Read(buffer,offset,count);
        }


     
    } // class FilterInputStream
}